home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00009_SimData Parent.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  29.0 KB  |  665 lines

  1. property columns, rows, cellHeight, cellWidth, NW, n, NE, w, E, SW, s, SE, moveList, truck1, roadTile1, river1, bridge1, rockTile, treeTile, valleyTile, partialTileList, cellHalfH, cellHalfV, gridLeft, gridTop, cellList, pathList, startCell, goalCell, dummyBitmap, scenarioList, recordedMoveList, blockedCellObj, firstNavButtonChan, demoButChan, dataCounter, simDataString, scenarioData, returnVehicle, sandboxChan, scenarioSong, gridSprite, firstSurroundSprite, underTruckSprite, destinationSprite, stampSprite, truckSprite, obstacleState, arrowList, deltaList, convertList, demoFlag, startSimFlag, simButtonList, finishedFlag, adjList, tileList, riverList, bridgeList, gridSize, covList, invisibleButtonList, firstInvisButChan, invisibleButCover, invisibleButHiliteChan, invisibleButHiliteBmap, cellTypeList, firstTime, buildingsConnected, paver1, bus1, car1
  2. global gActorList, gTruckObject, gGasGaugeObject, gUserObject, gLevelObject, gMenuObject, gAwardsObject, gRollAnimButton, gCDpath, gFileSep
  3.  
  4. on birth me
  5.   set scenarioList to [["house1", "house2", "library", "police", "store", "school", "bus", "PTW1"], ["house1", "store", "house2", "firehouse", "circus", "barn", "car", "PTW2"], ["house2", "house1", "bowling", "barn", "school", "library", "bus", "PTW3"], ["school", "library", "park", "police", "firehouse", "circus", "bus", "PTW4"], ["house1", "house2", "store", "police", "circus", "park", "car", "PTW5"], ["house2", "library", "house1", "firehouse", "store", "bowling", "car", "PTW6"]]
  6.   set scenarioSong to EMPTY
  7.   set firstTime to 1
  8.   set simButtonList to [:]
  9.   set firstInvisButChan to 2
  10.   set gridSprite to 10
  11.   set firstSurroundSprite to 11
  12.   set invisibleButtonList to [0, 0, 0, 0, 0, 0, 0, 0]
  13.   set invisibleButCover to 19
  14.   set invisibleButHiliteChan to 43
  15.   set underTruckSprite to 20
  16.   set destinationSprite to 21
  17.   set stampSprite to 22
  18.   set truckSprite to 23
  19.   set sandboxChan to 27
  20.   set firstNavButtonChan to 33
  21.   set demoButChan to 41
  22.   set gridSize to "Large"
  23.   set recordedMoveList to []
  24.   set buildingsConnected to 0
  25.   set obstacleState to EMPTY
  26.   set cellTypeList to [#BG, #Road, #immovable, #Rocks, #Valley, #River, #Bridge, #Building, #Goal]
  27.   set arrowList to [#n, #NE, #E, #SE, #s, #SW, #w, #NW]
  28.   set deltaList to [#n: [0, -1], #NE: [2, -1], #E: [2, 0], #SE: [2, 1], #s: [0, 1], #SW: [-2, 1], #w: [-2, 0], #NW: [-2, -1]]
  29.   set convertList to [#NW: #SE, #n: #s, #NE: #SW, #w: #E, #E: #w, #SW: #NE, #s: #n, #SE: #NW]
  30.   set river1 to the number of cast "C" - 1
  31.   set bridge1 to the number of cast "Bridge1" - 1
  32.   set rockTile to the number of cast "Rocks"
  33.   set valleyTile to the number of cast "Valley"
  34.   set demoFlag to 0
  35.   set startSimFlag to 1
  36.   set finishedFlag to 1
  37.   set adjList to [:]
  38.   addProp(adjList, "X", [#NW, #n, #NE, #w, #E, #SW, #s, #SE])
  39.   addProp(adjList, "N", [#w, #E, #SW, #s, #SE])
  40.   addProp(adjList, "N+", [#NW, #NE, #w, #E, #SW, #s, #SE])
  41.   addProp(adjList, "NE", [#w, #SW, #s])
  42.   addProp(adjList, "NE+", [#NW, #NE, #w, #SW, #s, #SE])
  43.   addProp(adjList, "E", [#NW, #n, #w, #SW, #s])
  44.   addProp(adjList, "E+", [#NW, #n, #NE, #w, #SW, #s, #SE])
  45.   addProp(adjList, "SE", [#NW, #n, #w])
  46.   addProp(adjList, "SE+", [#NW, #n, #NE, #w, #SW, #SE])
  47.   addProp(adjList, "S", [#NW, #n, #NE, #w, #E])
  48.   addProp(adjList, "S+", [#NW, #n, #NE, #w, #E, #SW, #SE])
  49.   addProp(adjList, "SW", [#n, #NE, #E])
  50.   addProp(adjList, "SW+", [#NW, #n, #NE, #E, #SW, #SE])
  51.   addProp(adjList, "W", [#n, #NE, #E, #s, #SE])
  52.   addProp(adjList, "W+", [#NW, #n, #NE, #E, #SW, #s, #SE])
  53.   addProp(adjList, "NW", [#E, #s, #SE])
  54.   addProp(adjList, "NW+", [#NW, #NE, #E, #SW, #s, #SE])
  55.   set tileList to [:]
  56.   addProp(tileList, #n, [#n: 20, #NE: 180, #E: 90, #SE: 140, #s: 20, #SW: 150, #w: 110, #NW: 190])
  57.   addProp(tileList, #NE, [#n: 170, #NE: 10, #E: 220, #SE: 60, #s: 150, #SW: 10, #w: 240, #NW: 50])
  58.   addProp(tileList, #E, [#n: 100, #NE: 210, #E: 30, #SE: 230, #s: 110, #SW: 240, #w: 30, #NW: 260])
  59.   addProp(tileList, #SE, [#n: 130, #NE: 40, #E: 200, #SE: 0, #s: 190, #SW: 50, #w: 260, #NW: 0])
  60.   addProp(tileList, #s, [#n: 20, #NE: 120, #E: 80, #SE: 160, #s: 20, #SW: 170, #w: 100, #NW: 130])
  61.   addProp(tileList, #SW, [#n: 120, #NE: 10, #E: 270, #SE: 70, #s: 180, #SW: 10, #w: 210, #NW: 40])
  62.   addProp(tileList, #w, [#n: 80, #NE: 270, #E: 30, #SE: 250, #s: 90, #SW: 220, #w: 30, #NW: 200])
  63.   addProp(tileList, #NW, [#n: 160, #NE: 70, #E: 250, #SE: 0, #s: 140, #SW: 60, #w: 230, #NW: 0])
  64.   set riverList to [#E: [#NE: 5, #SE: 6], #NE: [#NE: 2, #SE: 4, #E: 8], #SE: [#NE: 3, #SE: 1, #E: 7]]
  65.   set bridgeList to [:]
  66.   addProp(bridgeList, "A", [#NE: [1, #n], #n: [2, #n], #NW: [3, #n], #s: [2, #s], #E: [4, #n], #w: [5, #n]])
  67.   addProp(bridgeList, "B", [#n: [7, #n], #SE: [6, #s], #s: [7, #s], #SW: [8, #s], #E: [9, #s], #w: [10, #s]])
  68.   addProp(bridgeList, "C", [#n: [12, #n], #s: [12, #s], #E: [13, #E], #w: [13, #w], #NE: [11, #NE], #SW: [11, #SW]])
  69.   addProp(bridgeList, "D", [#n: [15, #n], #s: [15, #s], #E: [16, #E], #w: [16, #w], #NW: [14, #NW], #SE: [14, #SE]])
  70.   addProp(bridgeList, "E", [#n: [17, #n], #NW: [18, #n], #s: [17, #s], #w: [19, #n]])
  71.   addProp(bridgeList, "F", [#n: [20, #n], #SW: [21, #s], #s: [20, #s], #w: [22, #s]])
  72.   addProp(bridgeList, "G", [#n: [23, #n], #NE: [24, #n], #s: [23, #s], #E: [25, #n]])
  73.   addProp(bridgeList, "H", [#n: [26, #n], #SE: [27, #s], #s: [26, #s], #E: [28, #s]])
  74.   return me
  75. end
  76.  
  77. on initSizeVariables me
  78.   initCovList(me)
  79.   if gridSize = "Small" then
  80.     set columns to 8
  81.     set rows to 10
  82.     set cellHeight to 34
  83.     set cellWidth to 68
  84.     set gridLeft to 47
  85.     set gridTop to 20
  86.   else
  87.     set columns to 5
  88.     set rows to 6
  89.     set cellHeight to 56
  90.     set cellWidth to 112
  91.     set gridLeft to 39
  92.     set gridTop to 23
  93.   end if
  94.   set NW to -1 * columns
  95.   set n to (-2 * columns) + 1
  96.   set NE to (-1 * columns) + 1
  97.   set w to -1
  98.   set E to 1
  99.   set SW to columns - 1
  100.   set s to (2 * columns) - 1
  101.   set SE to columns
  102.   set moveList to [#NW: NW, #n: n, #NE: NE, #w: w, #E: E, #SW: SW, #s: s, #SE: SE]
  103.   set paver1 to the number of cast ("Ntruck" & gridSize)
  104.   set truck1 to paver1
  105.   set roadTile1 to the number of cast ("Tile1" & gridSize)
  106.   set treeTile to the number of cast ("Trees" & gridSize)
  107.   set dummyBitmap to the number of cast ("Dummy" & gridSize)
  108.   set invisibleButHiliteBmap to the number of cast ("InvisibleButHilite" & gridSize)
  109.   set partialTileList to [:]
  110.   repeat with dir in arrowList
  111.     addProp(partialTileList, dir, the number of cast ("Partial" & gridSize & dir))
  112.   end repeat
  113.   set cellHalfH to cellWidth / 2
  114.   set cellHalfV to cellHeight / 2
  115. end
  116.  
  117. on initCovList me
  118.   set covList to [:]
  119.   if gridSize = "Small" then
  120.     addProp(covList, "X", [#NW: [-7, -1, 7, 8, -16, -15], #n: [-8, -7, 7, 8, -23, -22], #NE: [-8, -15, 1, 7, 8, -14], #w: [-8, -7, 7, 8, -9, 6], #E: [-8, -7, 7, 8, -6, 9], #SW: [-8, -7, 8, 15, -1, 14], #s: [-8, -7, 8, 7, 22, 23], #SE: [-8, -7, 1, 15, 7, 16]])
  121.     addProp(covList, "N", [#w: [8, 7, 6], #E: [7, 8, 9], #SW: [-1, 15, 8, 1, 14], #s: [7, 8, 23, 22], #SE: [7, 15, 1, 16]])
  122.     addProp(covList, "N+", [#NW: [-7, -1, 7, 8], #NE: [-8, 1, 7, 8], #w: [-8, -7, 7, 8, -9, 6], #E: [-8, -7, 7, 8, -6, 9], #SW: [-8, -7, 8, 15, -1, 14], #s: [-8, -7, 8, 7, 22, 23], #SE: [-8, -7, 1, 15, 7, 16]])
  123.     addProp(covList, "NE", [#w: [7, 6], #SW: [-1, 15, 14], #s: [7, 22]])
  124.     addProp(covList, "NE+", [#NW: [-7, -1, 7, 8], #NE: [-8, 7, 8], #w: [-8, -7, 7, 8, -9, 6], #SW: [-8, -7, 8, 15, -1, 14], #s: [-8, -7, 8, 7, 22, 23], #SE: [-8, -7, 15, 7]])
  125.     addProp(covList, "E", [#NW: [-1, 7, -16, -15], #n: [-8, 7, -23], #w: [-8, 7, -9, 6], #SW: [-8, 15, -1, 14], #s: [-8, 7, 22]])
  126.     addProp(covList, "E+", [#NW: [-7, -1, 7, 8, -16, -15], #n: [-8, -7, 7, 8, -23, -22], #NE: [-8, -15, 7, 8], #w: [-8, -7, 7, 8, -9, 6], #SW: [-8, -7, 8, 15, -1, 14], #s: [-8, -7, 8, 7, 22, 23], #SE: [-8, -7, 15, 7]])
  127.     addProp(covList, "SE", [#NW: [-1, -16, -15], #n: [-8, -23], #w: [-8, -9]])
  128.     addProp(covList, "SE+", [#NW: [-7, -1, 7, 8, -16, -15], #n: [-8, -7, 7, 8, -23, -22], #NE: [-8, -15, 7, 8], #w: [-8, -7, 7, 8, -9, 6], #SW: [-8, -7, 8, -1], #SE: [-8, -7, 1, 7]])
  129.     addProp(covList, "S", [#NW: [-7, -1, -16, -15], #n: [-8, -7, -23, -22], #NE: [-8, -15, 1, -14], #w: [-8, -7, -9], #E: [-8, -7, -6]])
  130.     addProp(covList, "S+", [#NW: [-7, -1, 7, 8, -16, -15], #n: [-8, -7, 7, 8, -23, -22], #NE: [-8, -15, 1, 7, 8, -14], #w: [-8, -7, 7, 8, -9, 6], #E: [-8, -7, 7, 8, -6, 9], #SW: [-8, -7, 8, -1], #SE: [-8, -7, 1, 7]])
  131.     addProp(covList, "SW", [#n: [-7, -22], #NE: [-15, 1, -14], #E: [-7, -6]])
  132.     addProp(covList, "SW+", [#NW: [-7, 7, 8, -15], #n: [-8, -7, 7, 8, -23, -22], #NE: [-8, -15, 1, 7, 8, -14], #E: [-8, -7, 7, 8, -6, 9], #SW: [-8, -7, 8], #SE: [-8, -7, 1, 7]])
  133.     addProp(covList, "W", [#n: [-7, 8, -22], #NE: [-15, 1, 8, -14], #E: [-7, 8, -6, 9], #s: [-7, 8, 23], #SE: [-7, 1, 15, 16]])
  134.     addProp(covList, "W+", [#NW: [-7, 7, 8, -15], #n: [-8, -7, 7, 8, -23, -22], #NE: [-8, -15, 1, 7, 8, -14], #E: [-8, -7, 7, 8, -6, 9], #SW: [-8, -7, 8, 15], #s: [-8, -7, 8, 7, 22, 23], #SE: [-8, -7, 1, 15, 7, 16]])
  135.     addProp(covList, "NW", [#E: [8, 9], #s: [8, 9], #SE: [1, 15, 16]])
  136.     addProp(covList, "NW+", [#NW: [-7, 7, 8], #NE: [-8, 1, 7, 8], #E: [-8, -7, 7, 8, -6, 9], #SW: [-8, -7, 8, 15], #s: [-8, -7, 8, 7, 22, 23], #SE: [-8, -7, 1, 15, 7, 16]])
  137.   else
  138.     addProp(covList, "X", [#NW: [-4, -1, 4, 5, -10, -9], #n: [-5, -4, 4, 5, -14, -13], #NE: [-5, -9, 1, 4, 5, -8], #w: [-5, -4, 4, 5, -6, 3], #E: [-5, -4, 4, 5, -3, 6], #SW: [-5, -4, 5, 9, -1, 8], #s: [-5, -4, 5, 4, 13, 14], #SE: [-5, -4, 1, 9, 4, 10]])
  139.     addProp(covList, "N", [#w: [5, 4, 3], #E: [4, 5, 6], #SW: [-1, 9, 5, 1, 8], #s: [4, 5, 14, 13], #SE: [4, 9, 1, 10]])
  140.     addProp(covList, "N+", [#NW: [-4, -1, 4, 5], #NE: [-5, 1, 4, 5], #w: [-5, -4, 4, 5, -6, 3], #E: [-5, -4, 4, 5, -3, 6], #SW: [-5, -4, 5, 9, -1, 8], #s: [-5, -4, 5, 4, 13, 14], #SE: [-5, -4, 1, 9, 4, 10]])
  141.     addProp(covList, "NE", [#w: [4, 3], #SW: [-1, 9, 8], #s: [4, 13]])
  142.     addProp(covList, "NE+", [#NW: [-4, -1, 4, 5], #NE: [-5, 4, 5], #w: [-5, -4, 4, 5, -6, 3], #SW: [-5, -4, 5, 9, -1, 8], #s: [-5, -4, 5, 4, 13, 14], #SE: [-5, -4, 9, 4]])
  143.     addProp(covList, "E", [#NW: [-1, 4, -10, -9], #n: [-5, 4, -14], #w: [-5, 4, -6, 3], #SW: [-5, 9, -1, 8], #s: [-5, 4, 13]])
  144.     addProp(covList, "E+", [#NW: [-4, -1, 4, 5, -10, -9], #n: [-5, -4, 4, 5, -14, -13], #NE: [-5, -9, 4, 5], #w: [-5, -4, 4, 5, -6, 3], #SW: [-5, -4, 5, 9, -1, 8], #s: [-5, -4, 5, 4, 13, 14], #SE: [-5, -4, 9, 4]])
  145.     addProp(covList, "SE", [#NW: [-1, -10, -9], #n: [-5, -14], #w: [-5, -6]])
  146.     addProp(covList, "SE+", [#NW: [-4, -1, 4, 5, -10, -9], #n: [-5, -4, 4, 5, -14, -13], #NE: [-5, -9, 4, 5], #w: [-5, -4, 4, 5, -6, 3], #SW: [-5, -4, 5, -1], #SE: [-5, -4, 1, 4]])
  147.     addProp(covList, "S", [#NW: [-4, -1, -10, -9], #n: [-5, -4, -14, -13], #NE: [-5, -9, 1, -8], #w: [-5, -4, -6], #E: [-5, -4, -3]])
  148.     addProp(covList, "S+", [#NW: [-4, -1, 4, 5, -10, -9], #n: [-5, -4, 4, 5, -14, -13], #NE: [-5, -9, 1, 4, 5, -8], #w: [-5, -4, 4, 5, -6, 3], #E: [-5, -4, 4, 5, -3, 6], #SW: [-5, -4, 5, -1], #SE: [-5, -4, 1, 4]])
  149.     addProp(covList, "SW", [#n: [-4, -13], #NE: [-9, 1, -8], #E: [-4, -3]])
  150.     addProp(covList, "SW+", [#NW: [-4, 4, 5, -9], #n: [-5, -4, 4, 5, -14, -13], #NE: [-5, -9, 1, 4, 5, -8], #E: [-5, -4, 4, 5, -3, 6], #SW: [-5, -4, 5], #SE: [-5, -4, 1, 4]])
  151.     addProp(covList, "W", [#n: [-4, 5, -13], #NE: [-9, 1, 5, -8], #E: [-4, 5, -3, 6], #s: [-4, 5, 14], #SE: [-4, 1, 9, 10]])
  152.     addProp(covList, "W+", [#NW: [-4, 4, 5, -9], #n: [-5, -4, 4, 5, -14, -13], #NE: [-5, -9, 1, 4, 5, -8], #E: [-5, -4, 4, 5, -3, 6], #SW: [-5, -4, 5, 9], #s: [-5, -4, 5, 4, 13, 14], #SE: [-5, -4, 1, 9, 4, 10]])
  153.     addProp(covList, "NW", [#E: [5, 6], #s: [5, 6], #SE: [1, 9, 10]])
  154.     addProp(covList, "NW+", [#NW: [-4, 4, 5], #NE: [-5, 1, 4, 5], #E: [-5, -4, 4, 5, -3, 6], #SW: [-5, -4, 5, 9], #s: [-5, -4, 5, 4, 13, 14], #SE: [-5, -4, 1, 9, 4, 10]])
  155.   end if
  156. end
  157.  
  158. on initializeGrid me
  159.   set gridLeft2 to gridLeft + cellHalfH
  160.   set gridTop2 to gridTop + cellHalfV
  161.   set maxX to gridLeft + ((columns - 1) * cellWidth)
  162.   set maxY to gridTop + ((rows - 1) * cellHeight)
  163.   set cellList to []
  164.   set cell to 1
  165.   set vertVal to 1
  166.   add(cellList, birth(script "Cell Parent", cell, "NW", gridLeft, gridTop, 1, vertVal))
  167.   set cell to cell + 1
  168.   repeat with x = 1 to columns - 2
  169.     add(cellList, birth(script "Cell Parent", cell, "N", gridLeft + (x * cellWidth), gridTop, ((x + 1) * 2) - 1, vertVal))
  170.     set cell to cell + 1
  171.   end repeat
  172.   add(cellList, birth(script "Cell Parent", cell, "NE", maxX, gridTop, (columns * 2) - 1, vertVal))
  173.   set cell to cell + 1
  174.   set vertVal to 2
  175.   add(cellList, birth(script "Cell Parent", cell, "NW+", gridLeft2, gridTop2, 2, vertVal))
  176.   set cell to cell + 1
  177.   repeat with x = 1 to columns - 3
  178.     add(cellList, birth(script "Cell Parent", cell, "N+", gridLeft2 + (x * cellWidth), gridTop2, (x + 1) * 2, vertVal))
  179.     set cell to cell + 1
  180.   end repeat
  181.   add(cellList, birth(script "Cell Parent", cell, "NE+", maxX - cellHalfH, gridTop2, (columns - 1) * 2, vertVal))
  182.   set cell to cell + 1
  183.   set curV to gridTop + cellHalfH
  184.   set rowOddEven to 1
  185.   repeat with vertVal = 3 to (rows * 2) - 3
  186.     if rowOddEven = 1 then
  187.       add(cellList, birth(script "Cell Parent", cell, "W", gridLeft, curV, 1, vertVal))
  188.       set cell to cell + 1
  189.       repeat with y = 1 to columns - 2
  190.         add(cellList, birth(script "Cell Parent", cell, "X", gridLeft + (y * cellWidth), curV, ((y + 1) * 2) - 1, vertVal))
  191.         set cell to cell + 1
  192.       end repeat
  193.       add(cellList, birth(script "Cell Parent", cell, "E", maxX, curV, (columns * 2) - 1, vertVal))
  194.       set cell to cell + 1
  195.       set rowOddEven to 0
  196.     else
  197.       add(cellList, birth(script "Cell Parent", cell, "W+", gridLeft + cellHalfH, curV, 2, vertVal))
  198.       set cell to cell + 1
  199.       repeat with y = 1 to columns - 3
  200.         add(cellList, birth(script "Cell Parent", cell, "X", gridLeft2 + (y * cellWidth), curV, (y + 1) * 2, vertVal))
  201.         set cell to cell + 1
  202.       end repeat
  203.       add(cellList, birth(script "Cell Parent", cell, "E+", maxX - cellHalfH, curV, (columns - 1) * 2, vertVal))
  204.       set cell to cell + 1
  205.       set rowOddEven to 1
  206.     end if
  207.     set curV to curV + cellHalfV
  208.   end repeat
  209.   set vertVal to (rows * 2) - 2
  210.   add(cellList, birth(script "Cell Parent", cell, "SW+", gridLeft2, maxY - cellHalfV, 2, vertVal))
  211.   set cell to cell + 1
  212.   repeat with x = 1 to columns - 3
  213.     add(cellList, birth(script "Cell Parent", cell, "S+", gridLeft2 + (x * cellWidth), maxY - cellHalfV, (x + 1) * 2, vertVal))
  214.     set cell to cell + 1
  215.   end repeat
  216.   add(cellList, birth(script "Cell Parent", cell, "SE+", maxX - cellHalfH, maxY - cellHalfV, (columns - 1) * 2, vertVal))
  217.   set cell to cell + 1
  218.   set vertVal to (rows * 2) - 1
  219.   add(cellList, birth(script "Cell Parent", cell, "SW", gridLeft, maxY, 1, vertVal))
  220.   set cell to cell + 1
  221.   repeat with x = 1 to columns - 2
  222.     add(cellList, birth(script "Cell Parent", cell, "S", gridLeft + (x * cellWidth), maxY, ((x + 1) * 2) - 1, vertVal))
  223.     set cell to cell + 1
  224.   end repeat
  225.   add(cellList, birth(script "Cell Parent", cell, "SE", maxX, maxY, (columns * 2) - 1, vertVal))
  226. end
  227.  
  228. on newTruck
  229.   set adjacentCellList to the adjacentList of getAt(cellList, startCell)
  230.   set direction to getAt(adjacentCellList, random(count(adjacentCellList)))
  231.   set firstCell to startCell + getProp(moveList, direction)
  232.   initTruckProps(gTruckObject, firstCell, direction)
  233.   set cellObj to getAt(cellList, startCell)
  234.   set startName to getAt(scenarioData, 1)
  235.   set startTile to the number of cast (startName & "." & gridSize)
  236.   set startRoadtile to startTile + 8 + getPos(arrowList, direction)
  237.   set the tileNum of cellObj to startRoadtile
  238.   set the tileType of cellObj to #Goal
  239.   set the startTileNum of cellObj to startRoadtile
  240.   set the startTileType of cellObj to #Goal
  241. end
  242.  
  243. on placeGoals
  244.   set goalCell to random(columns)
  245.   if gridSize = "Small" then
  246.     if goalCell > 4 then
  247.       set startCell to random(4) + 135
  248.     else
  249.       set startCell to random(4) + 139
  250.     end if
  251.   else
  252.     if goalCell > 3 then
  253.       set startCell to random(3) + 45
  254.     else
  255.       set startCell to random(2) + 48
  256.     end if
  257.   end if
  258.   set cellObj to getAt(cellList, goalCell)
  259.   set goalName to getAt(scenarioData, 6)
  260.   set goalTile to the number of cast (goalName & "." & gridSize)
  261.   set the tileNum of cellObj to goalTile
  262.   set the tileType of cellObj to #Goal
  263.   set the startTileNum of cellObj to goalTile
  264.   set the startTileType of cellObj to #Goal
  265. end
  266.  
  267. on erasePlayfield me
  268.   global gGasGaugeObject, gLevelObject
  269.   if the level of gLevelObject = 3 then
  270.     set the currentV of gGasGaugeObject to the maxV of gGasGaugeObject
  271.     updateGasGauge(gGasGaugeObject)
  272.   end if
  273.   set the locH of sprite underTruckSprite to 1000
  274.   set the locH of sprite destinationSprite to 1000
  275.   set the locH of sprite truckSprite to 1000
  276.   set the locH of sprite stampSprite to the locH of sprite gridSprite
  277.   set the locV of sprite stampSprite to the locV of sprite gridSprite
  278.   set the castNum of sprite stampSprite to the castNum of sprite gridSprite
  279.   updateStage()
  280.   clearCoverTiles()
  281.   set the castNum of sprite stampSprite to 0
  282.   set the locH of sprite stampSprite to 1000
  283.   updateStage()
  284. end
  285.  
  286. on newGame me
  287.   set scenarioData to getAt(scenarioList, random(count(scenarioList)))
  288.   set returnVehicle to the number of cast (getAt(scenarioData, 7) & gridSize)
  289.   set scenarioSong to getAt(scenarioData, 8)
  290.   set finishedFlag to 0
  291.   set startSimFlag to 1
  292.   set demoFlag to 0
  293.   set buildingsConnected to 0
  294.   placeGoals()
  295.   newTruck()
  296.   if the level of gLevelObject = 1 then
  297.     set pathList to placeBuildings()
  298.     placeObstacle([#immovable, treeTile, 6, 40])
  299.   else
  300.     if the level of gLevelObject = 2 then
  301.       set pathList to placeBuildings()
  302.       placeObstacle([#immovable, treeTile, 6, #Rocks, rockTile, 3, 40])
  303.     else
  304.       drawRiver()
  305.       set pathList to placeBuildings()
  306.       resetGasGauge(gGasGaugeObject, count(pathList))
  307.       placeObstacle([#immovable, treeTile, 6, #Rocks, rockTile, 3, #Valley, valleyTile, 1, 40])
  308.     end if
  309.   end if
  310.   removeMessage()
  311.   set availableMoveList to createAvailableList(gTruckObject, the cell of gTruckObject)
  312.   refreshControls(availableMoveList)
  313.   placeInvisibleButtons(me, availableMoveList)
  314.   redrawBG(me)
  315.   drawTruck(gTruckObject)
  316.   simIntroSong()
  317. end
  318.  
  319. on initializeSimButtons me
  320.   if firstTime = 1 then
  321.     repeat with x = 1 to count(arrowList)
  322.       set channel to firstNavButtonChan + x - 1
  323.       addProp(simButtonList, getAt(arrowList, x), birth(script "Button Parent", channel, the locH of sprite channel, the locV of sprite channel, the castNum of sprite channel, 1))
  324.     end repeat
  325.     addProp(simButtonList, #Demo, birth(script "Button Parent", demoButChan, the locH of sprite demoButChan, the locV of sprite demoButChan, the castNum of sprite demoButChan, 1))
  326.     addProp(simButtonList, #alert, birth(script "Button Parent", 48, the locH of sprite 48, the locH of sprite 48, the castNum of sprite 48, 0))
  327.     set firstTime to 0
  328.   end if
  329. end
  330.  
  331. on hideSprites me
  332.   set the locH of sprite underTruckSprite to the locH of sprite underTruckSprite + 1000
  333.   puppetSprite(underTruckSprite, 1)
  334.   set the locH of sprite destinationSprite to the locH of sprite destinationSprite + 1000
  335.   puppetSprite(destinationSprite, 1)
  336.   set channel to the channel of gTruckObject
  337.   set the locH of sprite channel to the locH of sprite channel + 1000
  338.   puppetSprite(channel, 1)
  339. end
  340.  
  341. on redrawBG me
  342.   repeat with x = 1 to count(cellList)
  343.     set cellObj to getAt(cellList, x)
  344.     redrawCell(cellObj, stampSprite)
  345.     updateStage()
  346.   end repeat
  347. end
  348.  
  349. on isRoadFinished me
  350.   set truck1 to paver1
  351.   if finishedFlag = 1 then
  352.     if demoFlag <> 1 then
  353.       if buildingsConnected = (the level of gLevelObject + 1) then
  354.         roadCongrats()
  355.         set buildingsConnected to 0
  356.         simAward(gAwardsObject)
  357.         unpuppetAll()
  358.         keepSandboxBut(sandboxChan)
  359.         puppetPalette("SimPal")
  360.         go("Grass")
  361.         unLoadCast()
  362.         go(the frame + 1)
  363.         puppetPalette("AwardsPal", 60)
  364.         updateStage()
  365.         puppetPalette(0)
  366.         predraw(gAwardsObject)
  367.         go("SimAward")
  368.         puppetSprite(48, 0)
  369.       else
  370.         sound playFile 1, gCDpath & "SOUND" & gFileSep & "SIM" & gFileSep & "10VOBLDG"
  371.         set buildingsConnected to 0
  372.         repeat while soundBusy(1)
  373.         end repeat
  374.         afterPlayback()
  375.       end if
  376.     else
  377.       afterPlayback()
  378.     end if
  379.   end if
  380. end
  381.  
  382. on puppetTruckSprites me, trueOrFalse
  383.   puppetSprite(underTruckSprite, trueOrFalse)
  384.   puppetSprite(destinationSprite, trueOrFalse)
  385.   puppetSprite(truckSprite, trueOrFalse)
  386. end
  387.  
  388. on predrawSimButtons me
  389.   repeat with x = 1 to count(simButtonList)
  390.     set buttonObject to getAt(simButtonList, x)
  391.     set channel to the channel of buttonObject
  392.     set the castNum of sprite channel to the bmap of buttonObject
  393.     if the available of buttonObject = 1 then
  394.       set the locH of sprite channel to the locH of buttonObject
  395.     else
  396.       set the locH of sprite channel to 1000
  397.     end if
  398.     set the locV of sprite channel to the locV of buttonObject
  399.     puppetSprite(channel, 1)
  400.   end repeat
  401.   if the level of gLevelObject = 3 then
  402.     predrawGasGauge(gGasGaugeObject)
  403.   end if
  404. end
  405.  
  406. on lightButton me, moveName
  407.   set buttonChannel to the channel of getProp(simButtonList, moveName)
  408.   set the castNum of sprite buttonChannel to the castNum of sprite buttonChannel + 1
  409.   updateStage()
  410. end
  411.  
  412. on unlightButton me, moveName
  413.   set buttonChannel to the channel of getProp(simButtonList, moveName)
  414.   set the castNum of sprite buttonChannel to the castNum of sprite buttonChannel - 1
  415.   updateStage()
  416. end
  417.  
  418. on placeInvisibleButtons me, availableList, surroundFlag
  419.   if not (demoFlag or the playBack of gTruckObject) then
  420.     clearCoverTiles()
  421.     updateStage()
  422.     set truckCell to the cell of gTruckObject
  423.     repeat with x = 1 to count(invisibleButtonList)
  424.       set vector to getAt(arrowList, x)
  425.       if getPos(availableList, vector) <> 0 then
  426.         set channel to firstInvisButChan + x - 1
  427.         set cell to getAt(invisibleButtonList, x)
  428.         set newCell to truckCell + getProp(moveList, vector)
  429.         set cellObj to getAt(cellList, newCell)
  430.         if surroundFlag = 1 then
  431.           surroundStaticSprite(me, newCell, truckCell)
  432.           updateStage()
  433.         end if
  434.         set the locH of sprite channel to the Xloc of cellObj
  435.         set the locV of sprite channel to the Yloc of cellObj
  436.         updateStage()
  437.         setAt(invisibleButtonList, x, newCell)
  438.         next repeat
  439.       end if
  440.       setAt(invisibleButtonList, x, 0)
  441.     end repeat
  442.   end if
  443. end
  444.  
  445. on replaceInvisibleButtons me
  446.   clearCoverTiles()
  447.   updateStage()
  448.   set truckCell to the cell of gTruckObject
  449.   repeat with x = 1 to count(invisibleButtonList)
  450.     set vector to getAt(arrowList, x)
  451.     if getAt(invisibleButtonList, x) <> 0 then
  452.       set channel to firstInvisButChan + x - 1
  453.       set cell to getAt(invisibleButtonList, x)
  454.       set newCell to truckCell + getProp(moveList, vector)
  455.       set cellObj to getAt(cellList, newCell)
  456.       surroundStaticSprite(me, newCell, truckCell)
  457.       set the locH of sprite channel to the Xloc of cellObj
  458.       set the locV of sprite channel to the Yloc of cellObj
  459.       updateStage()
  460.     end if
  461.   end repeat
  462. end
  463.  
  464. on hideInvisibleButtons me
  465.   repeat with x = 1 to count(invisibleButtonList)
  466.     set cell to getAt(invisibleButtonList, x)
  467.     if cell <> 0 then
  468.       set cellObj to getAt(cellList, cell)
  469.       surroundStaticSprite(me, cell, the cell of gTruckObject)
  470.       updateStage()
  471.       set channel to firstInvisButChan + x - 1
  472.       set the locH of sprite channel to 1000
  473.       updateStage()
  474.     end if
  475.   end repeat
  476. end
  477.  
  478. on surroundStaticSprite me, cellNum, protectedCell
  479.   set cellObj to getAt(cellList, cellNum)
  480.   set coverList to []
  481.   set adjacentList to getProp(adjList, the cellType of cellObj)
  482.   repeat with vector in [#NW, #NE, #SE, #SW]
  483.     if getPos(adjacentList, vector) <> 0 then
  484.       if (cellNum + getProp(moveList, vector)) <> protectedCell then
  485.         add(coverList, vector)
  486.       end if
  487.     end if
  488.   end repeat
  489.   if cellNum <> protectedCell then
  490.     redrawCell(getAt(cellList, cellNum), firstSurroundSprite)
  491.     updateStage()
  492.   end if
  493.   repeat with x = 1 to count(coverList)
  494.     set vector to getAt(coverList, x)
  495.     set adjCell to cellNum + getProp(moveList, vector)
  496.     redrawCell(getAt(cellList, adjCell), firstSurroundSprite + x)
  497.   end repeat
  498.   updateStage()
  499. end
  500.  
  501. on fixTile me
  502.   set the locH of sprite stampSprite to the locH of sprite underTruckSprite
  503.   set the locV of sprite stampSprite to the locV of sprite underTruckSprite
  504.   set the castNum of sprite stampSprite to the castNum of sprite underTruckSprite
  505.   updateStage()
  506. end
  507.  
  508. on loadSim me, index
  509.   set dataCounter to index
  510.   set firstTime to readData(me)
  511.   if firstTime = 0 then
  512.     repeat with cellObj in cellList
  513.       loadCell(cellObj)
  514.     end repeat
  515.     set recordedMoveList to []
  516.     set moveListLength to readData(me)
  517.     repeat with x = 1 to moveListLength
  518.       set oneMove to getAt(arrowList, readData(me))
  519.       add(recordedMoveList, oneMove)
  520.     end repeat
  521.     set startSimFlag to readData(me)
  522.     set finishedFlag to readData(me)
  523.     set pathCount to readData(me)
  524.     set pathList to [:]
  525.     repeat with x = 1 to pathCount
  526.       set propName to getAt(arrowList, readData(me))
  527.       set cellNum to readData(me)
  528.       addProp(pathList, propName, cellNum)
  529.     end repeat
  530.     set startCell to readData(me)
  531.     set goalCell to readData(me)
  532.     set simButtonList to [#n: 0, #NE: 0, #E: 0, #SE: 0, #s: 0, #SW: 0, #w: 0, #NW: 0, #Demo: 0, #alert: 0]
  533.     repeat with x = 1 to count(simButtonList)
  534.       set avail to readData(me)
  535.       set chanNum to readData(me)
  536.       set Xloc to readData(me)
  537.       set Yloc to readData(me)
  538.       set bmap to readData(me)
  539.       setAt(simButtonList, x, birth(script "Button Parent", chanNum, Xloc, Yloc, bmap, avail))
  540.     end repeat
  541.     set buildingsConnected to readData(me)
  542.     set returnVehicle to readData(me)
  543.   end if
  544.   return dataCounter
  545. end
  546.  
  547. on saveSim me
  548.   set simDataString to EMPTY
  549.   appendData(me, firstTime)
  550.   if firstTime = 0 then
  551.     repeat with cellObject in cellList
  552.       appendData(me, saveCell(cellObject))
  553.     end repeat
  554.     appendData(me, count(recordedMoveList))
  555.     repeat with vector in recordedMoveList
  556.       appendData(me, getPos(arrowList, vector))
  557.     end repeat
  558.     appendData(me, startSimFlag)
  559.     appendData(me, finishedFlag)
  560.     appendData(me, count(pathList))
  561.     repeat with x = 1 to count(pathList)
  562.       appendData(me, getPos(arrowList, getPropAt(pathList, x)))
  563.       appendData(me, getAt(pathList, x))
  564.     end repeat
  565.     appendData(me, startCell)
  566.     appendData(me, goalCell)
  567.     repeat with buttonObject in simButtonList
  568.       appendData(me, saveButton(buttonObject))
  569.     end repeat
  570.     appendData(me, buildingsConnected)
  571.     appendData(me, returnVehicle)
  572.   end if
  573.   set simData to simDataString
  574.   set simDataString to EMPTY
  575.   return simData
  576. end
  577.  
  578. on setup me
  579.   preloadVehicle(gTruckObject, truck1)
  580.   if demoFlag <> 1 then
  581.     createGlobalButtons(me)
  582.   end if
  583.   initializeSimButtons(me)
  584.   if obstacleState = EMPTY then
  585.     if finishedFlag = 1 then
  586.       newGameAlert()
  587.       updateStage()
  588.       initializeGrid(me)
  589.       newGame(me)
  590.     else
  591.       set availableMoveList to createAvailableList(gTruckObject, the cell of gTruckObject)
  592.       placeInvisibleButtons(me, availableMoveList, 0)
  593.       redrawBG(me)
  594.       drawTruck(gTruckObject)
  595.       refreshControls(availableMoveList)
  596.     end if
  597.   else
  598.     redrawBG(me)
  599.     surroundSprite(the cell of gTruckObject, the newMove of gTruckObject)
  600.     set the locH of sprite underTruckSprite to the locH of sprite underTruckSprite - 1000
  601.     set the castNum of sprite destinationSprite to the tileNum of the blockedCellObj of gTruckObject
  602.     set the locH of sprite destinationSprite to the locH of sprite destinationSprite - 1000
  603.     restore(gTruckObject)
  604.     updateStage()
  605.     if (obstacleState = #Rocks) or (obstacleState = #Valley) then
  606.       part2ofMove(gTruckObject)
  607.       set obstacleState to EMPTY
  608.     else
  609.       if obstacleState = #River then
  610.         set the programmedMove of gTruckObject to #enterBridge
  611.         part2ofMove(gTruckObject)
  612.         set obstacleState to EMPTY
  613.         puppetAll()
  614.         go(the frame)
  615.         exit
  616.       end if
  617.     end if
  618.   end if
  619.   puppetAll()
  620. end
  621.  
  622. on createGlobalButtons me
  623.   add(gActorList, birth(script "Rollover Anim Button Class", "goMenu( gSimObject, me )", 27, 27, 5, "RCA-07VO01", "RCA-07RO01"))
  624.   add(gActorList, birth(script "Rollover Anim Button Class", "help( gSimObject, me )", 28, 28, 11, EMPTY, "RCA-05RO02"))
  625. end
  626.  
  627. on forgetObstacle me
  628.   deleteAt(recordedMoveList, count(recordedMoveList))
  629.   set cellObj to the cellObject of gTruckObject
  630.   if the tileType of cellObj = #Bridge then
  631.     checkForBridge(gTruckObject, cellObj)
  632.   end if
  633.   set the newMove of gTruckObject to getLast(recordedMoveList)
  634.   set the lastMove of gTruckObject to getLast(recordedMoveList)
  635.   set partialTile to getProp(partialTileList, the newMove of gTruckObject)
  636.   set cellObj to the cellObject of gTruckObject
  637.   set the tileNum of cellObj to partialTile + the connector of cellObj
  638.   set obstacleState to EMPTY
  639. end
  640.  
  641. on goMenu me, buttonObject
  642.   clearAllActors()
  643.   makeButtonJump(buttonObject)
  644.   puppetPalette("SimPal")
  645.   unpuppetAll()
  646.   go("Grass")
  647.   unLoadCast()
  648.   go(the frame + 1)
  649.   goLocationMap()
  650. end
  651.  
  652. on appendData me, datum
  653.   set simDataString to simDataString & string(datum) & ","
  654. end
  655.  
  656. on readData me
  657.   set datum to value(item dataCounter of the dataString of gMenuObject)
  658.   set dataCounter to dataCounter + 1
  659.   return datum
  660. end
  661.  
  662. on help me, buttonObject
  663.   birth(script "Help Parent", buttonObject, "Sim" & the level of gLevelObject)
  664. end
  665.